<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <link rel="stylesheet" type="text/css" href="./css/aui-slide.css" />
    <script type="text/javascript" src="./script/jquery.min.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/api.js"></script>
</head>

<body>
    <header class="aui-bar aui-bar-nav">
        <a class="aui-pull-left" tapmode onclick="closeWin()">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title">购买</div>
    </header>
    <div class="aui-bar-nav-d"></div>

    <div class="licai-buy-details-t">
        <p>新手体验</p>
        <p>预期收益年化：
            <p2 id="rate"></p2>% <span>投资限额： 100-1000元</span></p>
        <p>可购买剩余总额：665,100.00元</p>
    </div>

    <div class="licai-buy-details-m">
        <img src="image/licai-buy-details-m.png"> 投资金额（元）
        <span>￥<span2 id="money">100.00<span2></span>
    </div>

    <ul class="licai-buy-details-list">
      <li>
        投资周期：
        <label style="margin-right:2rem;"><input class="aui-checkbox" type="radio" name="Invest" id="Invest" checked='checked' value='7'> 7天</label>
        <label style="margin-right:2rem;"><input class="aui-checkbox" type="radio" name="Invest" id="Invest" value='15'> 15天</label>
        <label><input class="aui-checkbox" type="radio" name="Invest" id="Invest" value="30"> 30天</label>

      </li>
        <li>
            获利方式：每日利息
        </li>
        <li>
            预计收益：
            <li2 id="shouyi">
                <li2>
        </li>
        <li>
            实付金额：<span id="shifu"></span>
        </li>
    </ul>
    <!-- <div class="licai-buy-details-tk">
        <div class="aui-list-item-inner">
            <label><input class="aui-checkbox" type="checkbox" name="checkbox" id="checkbox_tiaokuan"> 同意</label>
            <p>
                <a>《借款协议》</a>
                <a>《委托授权书》</a>
                <a>《风险揭示书》</a>
                <a>《金可贷--电子签名数字证书用户申请确认函》</a>
            </p>
        </div>
    </div> -->
    <div class="licai-buy-details-d">
        <span class="jian" onclick="reducemoney();"></span>
        <select name="" id="select1">
        <option value="">x1</option>
        <option value="">x5</option>
        <option value="">x10</option>
    </select>
        <span class="jia" onclick="addmoney();"></span>
    </div>
    <div class="licai-d-btn-t"></div>
    <div class="licai-d-btn" onclick="submitData();">提交</div>


    <div class="licai-buy-box-bg">
        <div class="licai-buy-box">
            <h3>请填写交易密码</h3>
            <input type="password" name='paypassword' placeholder="请填写交易密码">
            <div class="licai-buy-box-btn">
                <a class="green" onclick="pay()">确定</a>
                <a class="green" onclick="licai_box_close()">取消</a>
            </div>
        </div>
    </div>



</body>
<script type="text/javascript">
    var true_money = '';
    var ex_rate = 0;
    var free_money = 0;
    var max_money = 0;
    // var times = 1;
    function licai_box_close() {
        $(".licai-buy-box-bg").hide();
    }
    apiready = function() {
        min_money_format_num = api.pageParam.min_money_format_num;
        rate = api.pageParam.rate;
        id = api.pageParam.id;
        max_money = api.pageParam.max_money;
        add_money = api.pageParam.add_money;

        true_money = min_money_format_num;

        $('#money').text(outputmoney(min_money_format_num));
        $('#rate').text(rate);
        changeShouyi(min_money_format_num);
        changeShifu();
    }


    function closeWin() {
        api.closeWin({});
    }

    function gesture() {
      api.openWin({
          name: 'h5unlock',
          url: './h5unlock.html',
          pageParam: {
              name: 'syx_buy_details'
          }
      });
    }

    function unlock() {
      pay();

    }

    function submitData() {
      var temp = $api.getStorage('open_gesture');
      // alert(temp);
      if (temp == 'true') {
          gesture();
      } else {
          $(".licai-buy-box-bg").show();
      }

        // if ($('#checkbox_tiaokuan').is(':checked')) {
        //     var temp = $api.getStorage('open_gesture');
        //     // alert(temp);
        //     if (temp == 'true') {
        //         gesture();
        //     } else {
        //         $(".licai-buy-box-bg").show();
        //     }
        //
        // } else {
        //     alert("请先阅读并同意条款！");
        // }
    }



    function addmoney() {
        var times = $("#select1  option:selected").text().substring(1);
        var money = parseInt($('#money').text().replace(/,/g, ''));

        if (money + add_money * times > max_money) {
            alert('最高可投金额为' + max_money + '元');
            $('#money').text(outputmoney(max_money));
            true_money = max_money;
            changeShouyi(max_money);
            changeShifu();
            return;
        }

        money = money + add_money * times;
        $('#money').text(outputmoney(money));
        true_money = money;
        changeShouyi(money);
        changeShifu();
    }

    function reducemoney() {
        var times = $("#select1  option:selected").text().substring(1);
        var money = parseInt($('#money').text().replace(/,/g, ''));
        if (min_money_format_num >= money) {
            alert('最低可投金额为' + outputmoney(min_money_format_num) + '元');
            $('#money').text(outputmoney(min_money_format_num));
            true_money = min_money_format_num;
            changeShouyi(min_money_format_num);
            changeShifu();
            return;
        }

        if (money > min_money_format_num * times) {
            money = money - add_money * times;
            $('#money').text(outputmoney(money));
            true_money = money;
            changeShouyi(money);
            changeShifu();
        } else {
            alert('最低可投金额为' + outputmoney(min_money_format_num) + '元');
            $('#money').text(outputmoney(min_money_format_num));
            true_money = min_money_format_num;
            changeShouyi(min_money_format_num);
            changeShifu();
            return;
        }
    }

    function sel_times(i) {
        $("b").each(function() {
            $(this).removeClass("active");
        });
        $(i).addClass("active");
        times = $(i).text().substring(1);
    }

     $(document).ready(function() {
     $('input[type=radio][name=Invest]').change(function() {

       var times = $("#select1  option:selected").text().substring(1);
       var money = parseInt($('#money').text().replace(/,/g, ''));

       changeShouyi(money);

            });
       });

    function changeShouyi(money) {
        // var radio = document.getElementsByName('huolifangshi');
        // for (i = 0; i < radio.length; i++) {
        //     if (radio[i].checked) {
        //         var type = radio[i].value;
        //     }
        // }
    var inv =  $("input[name='Invest']:checked").val();

        all_rate = parseFloat(rate) + parseFloat(ex_rate);

        var text='';
        if (inv =='7') {
          $('#shouyi').text('￥' + outputmoney(parseFloat(money) * parseFloat(parseFloat(all_rate).toFixed(2)) / 100 / 365 * 7));
        }else if (inv=='15') {
          $('#shouyi').text('￥' + outputmoney(parseFloat(money) * parseFloat(parseFloat(all_rate).toFixed(2)) / 100 / 365 * 15));
        }else if (inv=='30') {
          $('#shouyi').text('￥' + outputmoney(parseFloat(money) * parseFloat(parseFloat(all_rate).toFixed(2)) / 100 / 365 *30));

        }
        // $('#shouyi').text('￥' + outputmoney(parseFloat(money) * parseFloat(parseFloat(all_rate).toFixed(2)) / 100 / 365));
    }

    function changeShifu() {

        $('#shifu').text('￥' + outputmoney(parseInt(true_money) - parseInt(free_money)));
    }

    function pay() {
        var paypassword = '';
        var temp = $api.getStorage('open_gesture');
        if (temp == 'true') {
            paypassword = '';
        } else {
          $(".licai-buy-box-bg").hide();
            paypassword = $(" input[ name='paypassword' ] ").val();

        }

        api.showProgress({
            style: 'default',
            animationType: 'fade',
            title: '努力加载中...',
            text: '先喝杯茶...',
            modal: false
        });
        var userid = $api.getStorage('userid');
        // 5154
        url = webAddress + '/index.php?ctl=deal&act=dobid2';
        api.ajax({
            url: url,
            method: 'post',
            data: {
                values: {
                    ajax: '1',
                    agent: 'h5',
                    userid: userid,
                    id: id,
                    money: true_money,
                    hl_type: 2,
                    paypassword: paypassword
                }
            }
        }, function(ret, err) {
            if (ret) {
              console.log(JSON.stringify(ret));
              if (ret.status=='1') {
             openjump(ret);



              }else {
                alert(ret.info);
              }


            } else {
                alert(err.msg);
            }
        });
        api.hideProgress();
    }


    function openjump(data) {

      alert(JSON.stringify(data.info));
      api.openWin({
          name: 'jump',
          url: './jump.html',
          pageParam: {
              data: data.jump
          }
      });


    }

</script>

</html>
